package com.zggk.lzz.roadlist;


import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zggk.lzz.R;
import com.zggk.lzz.adapter.LGRecycleViewAdapter;
import com.zggk.lzz.adapter.LGViewHolder;
import com.zggk.lzz.mvp.MVPBaseActivity;
import com.zggk.lzz.roadmx.RoadMxActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;


/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */

public class RoadListActivity extends MVPBaseActivity<RoadListContract.View, RoadListPresenter> implements RoadListContract.View {

    @Bind(R.id.back)
    ImageView back;
    @Bind(R.id.title_text)
    TextView titleText;
    @Bind(R.id.cancle_button)
    TextView cancleButton;
    @Bind(R.id.recycle_view)
    RecyclerView recycleView;
    @Bind(R.id.wt_te)
    LinearLayout wtTe;
    @Bind(R.id.disease_new_parent_layout)
    RelativeLayout diseaseNewParentLayout;
    private LGRecycleViewAdapter<RoadListBean> adapter;
    private ArrayList<RoadListBean> ListDatas = new ArrayList<>();

    @Override
    public void onRequestError(String msg) {

    }

    @Override
    protected int getLayout() {
        return R.layout.act_road_list;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        setTitleText("路线列表");
        goBack();
        initData();
        initAdapter();
    }

    private void initAdapter() {
        recycleView.setHasFixedSize(true);
        recycleView.setNestedScrollingEnabled(false);
        LinearLayoutManager manager = new LinearLayoutManager(getContext());
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        recycleView.setLayoutManager(manager);
        adapter = new LGRecycleViewAdapter<RoadListBean>(ListDatas) {
            @Override
            public int getLayoutId(int viewType) {
                return R.layout.item_road_list;
            }

            @Override
            public void convert(LGViewHolder holder, RoadListBean zCDBean, int position) {
                holder.setText(R.id.lxbm_te, zCDBean.getLdbm());
                holder.setText(R.id.lxmc_te, zCDBean.getDs()+"-"+zCDBean.getQx());
                holder.setText(R.id.lc_te, zCDBean.getPrjType());
            }
        };
        recycleView.setAdapter(adapter);
        adapter.setOnItemClickListener(R.id.re_lay, new LGRecycleViewAdapter.ItemClickListener() {
            @Override
            public void onItemClicked(View view, int position) {
                Intent intent = new Intent(RoadListActivity.this, RoadMxActivity.class);
                intent.putExtra("roadCode",ListDatas.get(position).getLdbm());
                intent.putExtra("roadName",ListDatas.get(position).getDs()+"-"+ListDatas.get(position).getQx());
                intent.putExtra("qdzh",ListDatas.get(position).getQdzh());
                intent.putExtra("zdzh",ListDatas.get(position).getZdzh());
                intent.putExtra("lxcd",ListDatas.get(position).getLdzh());
                intent.putExtra("xmlx",ListDatas.get(position).getPrjType());
                startActivity(intent);
            }
        });
    }

    private void initData() {
        mPresenter.getData(RoadListActivity.this);
    }

    @Override
    public void getDatas(List<RoadListBean> roadListBeans) {
        ListDatas.addAll(roadListBeans);
        adapter.notifyDataSetChanged();
    }
}
